﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using TalentPools.Model;

namespace TalentPools.DAL
{
    public class RecordService
    {
        public bool DeleteRecord1(int resumeId)
        {
            string sql = "delete from record where resumeId=@resumeId";
            SqlParameter para = new SqlParameter("@resumeId", resumeId);
            return DBHelper.ExecuteNonQuery(CommandType.Text, sql, para) > 0;
        }
        public bool DeleteRecord(int recordId)
        {
            string sql = "delete from record where recordid=@recordid";
            SqlParameter para = new SqlParameter("@recordid", recordId);
            return DBHelper.ExecuteNonQuery(CommandType.Text, sql, para) == 1;
        }
        public List<record> GetRecord(int resumeId, int recordId)
        {
            string sql = "select * from record where recordid=@recordId and resumeId=@resumeId";
            SqlParameter[] paras = new SqlParameter[] { 
            new SqlParameter("@resumeId",resumeId),
            new SqlParameter("@recordId",recordId)
            };
            List<record> list = new List<record>();
            using (SqlDataReader dr = DBHelper.ExecuteGetReader(CommandType.Text, sql, paras))
            {
                while (dr.Read())
                {
                    record record = new record();
                    record.recordid = Convert.ToInt32(dr["recordid"]);
                    record.title = dr["title"].ToString();
                    record.beginTime = Convert.ToDateTime(dr["beginTime"]);
                    record.endTime = Convert.ToDateTime(dr["endTime"]);
                    record.content = dr["content"].ToString();
                    record.details = dr["details"].ToString();
                    list.Add(record);
                }
                return list;
            }
        }
        public List<record> GetRecord(int resumeId)
        {
            string sql = "select * from record where resumeId=@resumeId";
            SqlParameter para = new SqlParameter("@resumeId", resumeId);
            List<record> list = new List<record>();
            using (SqlDataReader dr=DBHelper.ExecuteGetReader(CommandType.Text,sql,para))
            {
                while (dr.Read())
                {
                    record record = new record();
                    record.recordid = Convert.ToInt32(dr["recordid"]);
                    record.title = dr["title"].ToString();
                    record.beginTime = Convert.ToDateTime(dr["beginTime"]);
                    record.endTime = Convert.ToDateTime(dr["endTime"]);
                    record.content = dr["content"].ToString();
                    record.details = dr["details"].ToString();
                    record.resumeId = Convert.ToInt32(dr["resumeId"]);
                    list.Add(record);
                }
                return list;
            }
            
        }
    }
}
